﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Stamp_For_Africa_Version_2.Models;

namespace Stamp_For_Africa_Version_2.Repositories
{
	public class CommentRepository
	{
		private StampsDataContext db = new StampsDataContext();
		//
		// Query Methods

		public IQueryable<Comment> FindAllComments()
		{
			return db.Comments;
		}

		public IQueryable<Comment> FindAllCommentsForStamp(Guid stampId)
		{
			//Filter code comes here
			return db.Comments.Where(u => u.StampId == stampId);

		}

		public IQueryable<Comment> FindAllCommentsForStampByUser(Guid stampId, Guid userId)
		{
			return db.Comments.Where(u => u.StampId == stampId && u.CommentBy == userId);
		}

		public IQueryable<Comment> FindAllCommentsByUser(Guid userId)
		{
			return db.Comments.Where(u => u.CommentBy == userId);
		}


		public Comment GetComment(Guid id)
		{
			return db.Comments.SingleOrDefault(d => d.Id == id);
		}

		//
		// Insert/Delete Methods

		public void Add(Comment comment)
		{						
			db.Comments.InsertOnSubmit(comment);
		}

		public void Delete(Comment comment)
		{
			db.Comments.DeleteOnSubmit(comment);
		}

		//
		// Persistence

		public void Save()
		{
			db.SubmitChanges();
		}
	}
}